package com.itheima;

import com.itheima.config.SpringConfig;
import com.itheima.dao.AccountDao;
import com.itheima.domain.Account;
import com.itheima.service.AccountService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.List;

/**
 * Description:
 *
 * @author codermao
 * @date 2023/11/3 15:08
 *
 *  TODO：Spring整合junit
 *
 *      1.实现：
 *          i）导包spring-test（5.2.10.RELEASE版本需要junit4.12版本以上）
 *          ii）代码编写
 *
 */
//SpringJUnit4ClassRunner替代junit原生执行器
@RunWith(SpringJUnit4ClassRunner.class)
//加载注解配置类的
@ContextConfiguration(classes= SpringConfig.class)
//加载xml配置
//@ContextConfiguration(value="classpath:applicationContext.xml")
public class MyTest2 {

    //直接从ioc容器中获取bean
    @Autowired
    AccountService service;

    //看似有错，其实idea识别不了高级用法
    @Autowired
    AccountDao dao;

    @Test
    public void test01(){
        List<Account> list = service.findAll();
        for (Account account : list) {
            System.out.println(account);
        }
    }

    @Test
    public void test02(){
        Account account = dao.findById(2);
        System.out.println(account);
    }
}
